package com.bolang.onlycode.demo.MyThread;

/**
 * 循环10次打印用join方法不太好
 */
public class LoopABCjoin {
    static class print implements Runnable{
        private Thread prevThread;
        public print(Thread thread){
            prevThread=thread;
        }
        @Override
        public void run() {
                if(prevThread!=null){
                    try {
                        prevThread.join();
                        System.out.println(Thread.currentThread().getName());
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }else {
                    System.out.println(Thread.currentThread().getName());
                }
            }
        }


    public static void main(String[] args) throws InterruptedException {
        Thread t1 =new Thread(new print(null),"A");
        Thread t2 =new Thread(new print(t1),"B");
        Thread t3 =new Thread(new print(t2),"C");
        t1.start();
        t2.start();
        t3.start();
    }
}
